home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / info-service / gopher / Unix / GopherTools / gee.shar / win.pl < prev   
Encoding:
Perl Script  |  1993-07-11  |  3.5 KB  |  127 lines

  1. # wjm@feenix.metronet.com
  2. #
  3. package win;
  4. # Window array has the following elements
  5. # (all coordinates are w.r.t. (1,1) = top left hand corner of screen
  6. #
  7. # @window=( 
  8. # llx,        # the lower-left x coordinate for the window  
  9. # lly,        # the lower-left y coordinate of the window
  10. # urx,        # the upper-right x coordinate of the window
  11. # ury,        # the upper right y coordinate of the window
  12. # nattr,      # the normal attribute for the window
  13. # hattr,      # the highlight attribute for the window
  14. # title       # current title text
  15. # footer      # current footer text
  16. # )
  17. # Associated with the window, at any given time is the current text
  18. # body.  we use another array.
  19. # @text=
  20. # line1,   # first line of text to be placed beneath header
  21. # line2,   # second line of text to be placed beneath footer
  22. # ...,
  23. # lineN,   # nth line of text, with n not to exceed lly - ury - 2
  24. # )
  25.  
  26. sub clear{                       # clear the complete window area
  27. local($llx,$lly,$urx,$ury,$attr) = @_;
  28. local($width,$height) = ($urx-$llx,$lly-$ury);
  29. eval <<'EOLoop';
  30. print "\e"."["."$attr"."m";      # set background attribute, usually black
  31. for($i = $ury;$i<=$lly;$i++){      
  32.   print "\e"."["."$i".";"."$llx"."f";  
  33.   print " " x $width;
  34. }
  35. EOLoop
  36. 1;
  37. }
  38.  
  39. sub refresh{                     # print the current buffer in window
  40. local(@buffer) = splice(@_,0,shift);
  41. local($llx,$lly,$urx,$ury,$attr,$nattr) = splice(@_,0,shift);
  42. local($i,$j,$tmp,$tmp2,$string);
  43. local($width,$height) = ($urx-$llx-1,$lly-$ury);
  44. $llx+=2;
  45. eval <<'EOLoop';
  46. print "\e"."["."$attr"."m";      
  47. for($i = $ury+1,$j=0;$i<$lly;$i++,$j++){      
  48.   #if($i==($lly-1)){if(defined($buffer[$j+1])){$j-=($i-1);$i=($ury+1);}}
  49.   $buffer[$j] =~ s/\t/   /g;
  50.   $tmp = $width - length($buffer[$j]);
  51.   print "\e"."["."$i".";"."$llx"."H";
  52.   if ($tmp < 2 )
  53.     {$string =substr($buffer[$j],0,$width-3);
  54.      print $string;}
  55.   else { 
  56.      print $buffer[$j];
  57.      print " " x ($tmp-2); }
  58.   }
  59. EOLoop
  60. }
  61.  
  62. sub title{         # highlight the top line, text is arg
  63. local($llx,$lly,$urx,$ury,$oattr,$nattr,$text) = @_; 
  64. local($width) = ($urx-$llx);
  65. $fill = $width - length($text);
  66. print "\e"."["."$ury".";"."$llx"."f";
  67. print "\e"."["."$nattr"."m";     
  68. print $text;                  
  69. print " " x $fill;
  70. }
  71.  
  72. sub footer{         # print a footer on the window with text
  73. local($llx,$lly,$urx,$ury,$oattr,$nattr,$junk,$text) = @_; 
  74. local($width) = ($urx-$llx);
  75. $fill = $width - length($text);
  76. print "\e"."["."$lly".";"."$llx"."f";
  77. print "\e"."["."$nattr"."m";     
  78. print $text;                  
  79. print " " x $fill;
  80. }
  81.  
  82. sub border{                   
  83. local($llx,$lly,$urx,$ury,$oattr,$nattr) = @_;
  84. local($width) = ($urx-$llx);
  85. local($i,$j);
  86. $ury+=1;
  87. eval <<'EOLoop';
  88. for($i = $ury;$i<$lly;$i++){      
  89.   print "\e"."["."$i".";"."$llx"."H";
  90.   print "\e"."["."$nattr"."m";      
  91.   print " ";                
  92.   print "\e"."["."$oattr"."m";      
  93.   print " " x ($width-2);
  94.   print "\e"."["."$nattr"."m";      
  95.   print " ";                
  96. }
  97. EOLoop
  98. 1;
  99. }
  100.  
  101.  
  102. sub highlight_field{                # highlight a field in current buffer
  103. local($row,$col,$field,$attr) = @_;
  104. print "\e"."["."$row".";"."$col"."f";
  105. print "\e"."["."$attr"."m";      
  106. print $field;                  
  107. }
  108.  
  109. sub getdata{                # get data from the keyboard      
  110. local($col,$row,$prompt,$attr) = @_;
  111. local($tmp)=length($prompt)+1;
  112. local($tmp2) = $tmp +$col;
  113. print "\e"."["."$row".";"."$col"."H";
  114. print "\e"."["."$attr"."m";      
  115. print $prompt;                  
  116. print "\e"."["."0"."m";      
  117. print "\e"."["."$row".";"."$tmp2"."H";
  118. $tmp = <STDIN>;
  119. }
  120. 1;
  121.  
  122. # bILL  -  wjm@decster.uta.edu
  123.  
  124.  
  125.